﻿using Engine.Objects.StaticObjects;
using Microsoft.Xna.Framework;
using ThinkDotNetEditorLib.Models.StaticObjects;
using ThinkDotNetEditorLib.States;

namespace ThinkDotNetEditorLib.Commands.Arena
{
    public class AddStaticObjectCmd:ICommand
    {
        private readonly StaticObjectInfo _staticObjectInfo;
        private readonly Vector3 _position;
        private StaticObject _addedObject;

        public AddStaticObjectCmd(Vector3 position, StaticObjectInfo staticObjectInfo)
        {
            _position = position;
            _staticObjectInfo = staticObjectInfo;
        }
        public void Execute()
        {
            Models.Arena arena = ServiceLocator.Instance.Resolve<Models.Arena>();
            if (_addedObject == null)
                _addedObject = arena.AddObject(_staticObjectInfo, _position);
            else
                arena.AddObject(_addedObject);
        }
        public void Rollback()
        {
            Models.Arena arena = ServiceLocator.Instance.Resolve<Models.Arena>();
            arena.RemoveObject(_addedObject);
        }
    }
}
